package ext.generic.erp.manually;

import wt.fc.Persistable;
import wt.fc.WTReference;
import wt.part.WTPart;

import com.ptc.core.ui.validation.DefaultUIComponentValidator;
import com.ptc.core.ui.validation.UIValidationCriteria;
import com.ptc.core.ui.validation.UIValidationKey;
import com.ptc.core.ui.validation.UIValidationStatus;

import ext.generic.erp.rule.BussinessRule;
import ext.generic.erp.util.PDMIntegrationLogUtil;

public class ErpManuallyPublishActionValidator extends DefaultUIComponentValidator {
	private static String clazz = ErpManuallyPublishActionValidator.class.getName() ;
	
	private static final String D_VIEW = "Design";
	
	public ErpManuallyPublishActionValidator() {
		
	}

	public UIValidationStatus preValidateAction(UIValidationKey uivalidationkey,UIValidationCriteria uivalidationcriteria) {
		UIValidationStatus uivalidationstatus = UIValidationStatus.HIDDEN;
		
		WTReference wtreference = uivalidationcriteria.getContextObject();
		
		if (wtreference != null) {
			Persistable persistable = wtreference.getObject();
			
			try {
				if ( persistable != null && persistable instanceof WTPart) {
					WTPart wtpart = (WTPart) persistable;					
					//修改原因：ERP集成中“Design”视图的零部件不用发到中间表
					if( !wtpart.getViewName().equals( D_VIEW ) ){
						
						//是否显示手工发布菜单
						boolean result = BussinessRule.showManuallyPublishMenu(wtpart) ;
						
						PDMIntegrationLogUtil.printLog(clazz, "showManuallyPublishMenu : " + result ) ;
						
						if ( result ) {
							uivalidationstatus =  UIValidationStatus.ENABLED;
						} else {
							uivalidationstatus = UIValidationStatus.HIDDEN;
						}
					}	
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return uivalidationstatus;
	}
}
